import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.StringTokenizer;

/*
ID: majowi1
LANG: JAVA
PROG: gift1
*/
final class gift1 {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException {
		
	    BufferedReader f = new BufferedReader(new FileReader("gift1.in"));	    
	    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("gift1.out")));
		
	    HashMap<String, Integer> people = new HashMap<String, Integer>();
	    int i1,i2,gift,left;
	    String currentperson, nextpresent;
	    String[] persons = new String[Integer.parseInt(f.readLine())];
	    
	  //build person list
	    for (int x = 0; x < persons.length; x++){
	    	currentperson = f.readLine();
	    	people.put(currentperson, 0);
	    	persons[x] = currentperson;	    	
	    }	    	
	    
	    while ((currentperson = f.readLine()) != null)  { //null if the end of the stream has been reached)
	    	//reset
	    	gift=0;left=0;
	    	//get the numbers	    	
	    	StringTokenizer st = new StringTokenizer(f.readLine());	    	
	    	i1 = Integer.parseInt(st.nextToken());    // first integer = giftsize
	    	i2 = Integer.parseInt(st.nextToken());    // second integer = no of persons to share with
	        //must not contain zero
	        if (i1 != 0 || i2 != 0){
	        	left = i1 % i2;
	        	gift = (i1-left) / i2;
	        }
	        //withdraw giftsize
	        people.put(currentperson, (people.get(currentperson)-i1));	        
	        //for each person you want to share with, deposit gift
	        for (int x = 0; x < i2; x++){
	        	nextpresent = f.readLine();	        	
	        	people.put(nextpresent, (people.get(nextpresent)+gift));
	        }	        
	        //deposit leftovers
	        people.put(currentperson, (people.get(currentperson)+left));
	    }	    
	    for (int x = 0; x < persons.length; x++)
	    	out.println(persons[x] + " " + people.get(persons[x]));
	    out.close();
	    System.exit(0);
	}

}
